package top.fullj.fsm;

import com.google.common.base.Preconditions;
import top.fullj.bean.ToString;

/**
 * @author bruce.wu
 * @since 2021/8/2 10:44
 */
public final class Condition {

    private final State state;
    private final Event event;

    public Condition(State state, Event event) {
        Preconditions.checkNotNull(state);
        Preconditions.checkNotNull(event);
        this.state = state;
        this.event = event;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Condition cond = (Condition) o;
        return state.equals(cond.state) && event.equals(cond.event);
    }

    @Override
    public int hashCode() {
        int result = state.hashCode();
        result = 31 * result + event.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return ToString.toStringHelper(this)
                .add("state", state)
                .add("event", event)
                .toString();
    }

}
